package com.chunshen.weibo.weibodemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.chunshen.weibo.weibodemo.R;
import com.chunshen.weibo.weibodemo.common.BaseApplication;

/**
 * Created by yanxiaoqiang on 2016/6/18.
 */

public abstract class BaseActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private RelativeLayout content;
    private ActionBar mActionBar;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
     //   Log.e("BaseActivity","");
        setContentView(R.layout.base_activity_layout);
        initids();
        View childView = LayoutInflater.from(this).inflate(getLayoutId(), null);
        content.addView(childView);
    }

    protected void initids() {
        content = (RelativeLayout) findViewById(R.id.content);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
//        toolbar.setNavigationIcon(R.mipmap.ic_launcher);//设置导航栏图标
//        toolbar.setLogo(R.mipmap.ic_launcher);//设置app logo
//        toolbar.setTitle("Title");//设置主标题
//        toolbar.setSubtitle("Subtitle");//设置子标题
//
//        toolbar.inflateMenu(R.menu.);//设置右上角的填充菜单
//        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
//            @Override
//            public boolean onMenuItemClick(MenuItem item) {
//                int menuItemId = item.getItemId();
//                if (menuItemId == R.id.action_search) {
//                    Toast.makeText(BaseActivity.this , R.string.app_name , Toast.LENGTH_SHORT).show();
//
//                } else if (menuItemId == R.id.action_notification) {
//                    Toast.makeText(BaseActivity.this , R.string.app_name , Toast.LENGTH_SHORT).show();
//
//                } else if (menuItemId == R.id.action_item1) {
//                    Toast.makeText(BaseActivity.this , R.string.app_name , Toast.LENGTH_SHORT).show();
//
//                } else if (menuItemId == R.id.action_item2) {
//                    Toast.makeText(BaseActivity.this , R.string.app_name , Toast.LENGTH_SHORT).show();
//
//                }
//                return true;
//            }
//        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    //获取子activity的view ID
    public abstract int getLayoutId();

    //获取activity
    public Activity getCurrentActivity() {
        return this;
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(R.anim.anim_in_left_right, R.anim.anit_out_left_right);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.anim_in_left_right, R.anim.anit_out_left_right);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        overridePendingTransition(R.anim.anim_in_left_right, R.anim.anit_out_left_right);
    }

    public Toolbar getToolBar() {
        if (toolbar == null) {
            toolbar = new Toolbar(BaseApplication.getApplicationContextx());
        }
            return toolbar;
    }

    public void hideToolBar() {
        mActionBar = this.getSupportActionBar();
        mActionBar.setDisplayHomeAsUpEnabled(true);
        mActionBar.hide();
    }
}
